<?php
/**
 * Disputeo mail class. For sending emails to users.
 * 
 * @package disputeo
 * @version 1.0
 * @author jimmy.dixon
 */

class Disputeo_Mail extends Zend_Mail
{
    /**
     * @var string
     */
    protected $_emailsDir;

    /**
     * Initialise email properties
     */
    public function __construct()
    {
        $this->_emailsDir = APPLICATION_PATH . '/../data/emails/';
        $this->setFrom('admin@disputeo.com', 'disputeo.com');
    }

    /**
     * Send 'welcome to disputeo' email to a user.
     * @param Application_Model_User $user
     */
    public function sendWelcomeEmail(Application_Model_User $user)
    {
        $message = file_get_contents($this->_emailsDir . 'welcome.txt');
        $message = str_replace('__USERNAME__', $user->getUsername(), $message);

        $this->setSubject('Welcome aboard!');
        $this->addTo($user->getEmail());
        $this->setBodyText($message);
        $this->send();
    }

    /**
     * Send 'reset password' email to a user.
     * @param Application_Model_User $user
     */
    public function sendPasswordEmail(Application_Model_User $user)
    {
        $message = file_get_contents($this->_emailsDir . 'password.txt');
        $message = str_replace('__USERNAME__', $user->getUsername(), $message);
        $message = str_replace('__RESETHASH__', $user->getPasswordReset()->getResetId(), $message);

        $this->setSubject('Password reset');
        $this->addTo($user->getEmail());
        $this->setBodyText($message);
        $this->send();
    }

}
